/*
 * ListCellRenderer.java
 * 
 * Copyright 2007 Tiberiumlabs
 *
 * This file is part of Tiberiumlabs Shards.
 *
 * Tiberiumlabs Shards is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Tiberiumlabs Shards is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.tiberiumlabs.shards.components;

import java.awt.Color;
import java.awt.Component;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import javax.swing.UIManager;

/**
 *
 * @author <a href="mailto:paranoid.tiberiumlabs@gmail.com">Paranoid</a>
 */
public class ListCellRenderer extends DefaultListCellRenderer.UIResource {
    
    private static Color ALTERNATIVE_BACKGROUND = null;
    static {
        if (ALTERNATIVE_BACKGROUND == null) {
            Color back = UIManager.getColor("List.alternativeBackground");
            if (back != null) {
                ALTERNATIVE_BACKGROUND = back;
            } else {
                ALTERNATIVE_BACKGROUND = new Color(240, 240, 240);
            }
        }
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        if (!isSelected && index % 2 != 0) {
            component.setBackground(ALTERNATIVE_BACKGROUND);
        }
        return component;
    }

}
